//
//  WJQNearbyTableViewCell.m
//  TripTogether
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 王军岐. All rights reserved.
//

#import "WJQNearbyTableViewCell.h"
#import "WJQNearbyModel.h"
#import "StarView.h"

@interface WJQNearbyTableViewCell ()

@property (nonatomic, retain) UIImageView *headImageV;

@property (nonatomic, retain) UILabel *nameLabel;

@property (nonatomic, retain) StarView *starView;

@property (nonatomic, strong) UILabel *ratingUsers; // 几个点评

@property (nonatomic, retain) UILabel *contentLabel;

@property (nonatomic, retain) UILabel *distance; // 距离

@property (nonatomic, strong) UILabel *recommendLabel; // 推荐

@end


@implementation WJQNearbyTableViewCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createSubViews];
    }
    return self;
}

- (void)createSubViews {
    
    _headImageV = [UIImageView new];
    _headImageV.backgroundColor = [UIColor whiteColor];
    _headImageV.layer.masksToBounds = YES;
    _headImageV.layer.cornerRadius = 6.f;
    _headImageV.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView addSubview:_headImageV];
    
    [_headImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(115, 115));
        make.top.mas_equalTo(@15);
        make.left.mas_equalTo(@17);
    }];
    
    _recommendLabel = [UILabel new];
    _recommendLabel.backgroundColor = [UIColor colorWithRed:0.94 green:0.4 blue:0.01 alpha:1];
    _recommendLabel.text = @"推荐";
    _recommendLabel.textColor = [UIColor whiteColor];
    _recommendLabel.font = [UIFont boldSystemFontOfSize:11.f];
    _recommendLabel.textAlignment = NSTextAlignmentCenter;
    _recommendLabel.layer.masksToBounds = YES;
    _recommendLabel.layer.cornerRadius = 4.f;
    _recommendLabel.hidden = YES;
    [self.contentView addSubview:_recommendLabel];
    
    [_recommendLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.size.mas_equalTo(CGSizeMake(30, 20));
        make.left.mas_equalTo(_headImageV).offset(-1.5);
        make.top.mas_equalTo(_headImageV).offset(15);
        
    }];
    
    
    
    _nameLabel = [UILabel new];
//    _nameLabel.backgroundColor = [UIColor orangeColor];
    _nameLabel.textColor = [UIColor colorWithRed:0.35 green:0.35 blue:0.35 alpha:1];
    _nameLabel.font = [UIFont fontWithName:@"Bradley Hand" size:21.f];
    [self.contentView addSubview:_nameLabel];
    
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(_headImageV.mas_right).offset(10);
        make.top.mas_equalTo(_headImageV.mas_top).offset(-5);
        make.right.mas_equalTo(@(-20));
        make.height.mas_equalTo(@30);
    }];
    
   
    self.starView = [[StarView alloc] initWithFrame:CGRectMake(17 + 115 + 10, 10 + 30 + 3, 15, 15) number:5];
    [self.contentView addSubview:self.starView];
    
    
    _ratingUsers = [UILabel new];
    _ratingUsers.textColor = [UIColor colorWithRed:0.73 green:0.72 blue:0.7 alpha:1];
//    _ratingUsers.backgroundColor = [UIColor orangeColor];
    _ratingUsers.font = [UIFont systemFontOfSize:14.5f];
//    _ratingUsers.font = [UIFont fontWithName:@"Khmer Sangam MN" size:14.5f];
    [self.contentView addSubview:_ratingUsers];
    
    [_ratingUsers mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(@(17 + 115 + 10 + ((15 + 5) * 5)));
        make.right.mas_equalTo(_nameLabel);
        make.height.mas_equalTo(@15);
        make.top.mas_equalTo(@(10 + 30 + 3));
        
    }];
    
    
    _contentLabel = [UILabel new];
    _contentLabel.backgroundColor = [UIColor clearColor];
    _contentLabel.font = _ratingUsers.font;
    _contentLabel.numberOfLines = 0;
    _contentLabel.textColor = _ratingUsers.textColor;
    [self.contentView addSubview:_contentLabel];
    
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(_nameLabel);
        make.top.mas_equalTo(_starView.mas_bottom).offset(3);
        make.height.mas_equalTo(@45);
        make.width.equalTo(_nameLabel.mas_width).offset(-8);
    }];
    
    
    
    _distance = [UILabel new];
//    _distance.backgroundColor = [UIColor orangeColor];
    _distance.font = _ratingUsers.font;
    _distance.textColor = _ratingUsers.textColor;
    [self.contentView addSubview:_distance];
    
    [_distance mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(_headImageV);
        make.left.and.right.mas_equalTo(_nameLabel);
        
    }];
    
//    UIView *view = [UIView new];
//    view.backgroundColor = [UIColor lightGrayColor];
//    [self.contentView addSubview:view];
//    
//    [view mas_makeConstraints:^(MASConstraintMaker *make) {
//        
//        make.left.right.mas_equalTo(@0);
//        make.height.mas_equalTo(@2);
//        make.bottom.mas_equalTo(@-2);
//    }];
    
}
- (void)setOther:(WJQNearbyModel *)other
{
    
    NSURL *url = [NSURL URLWithString:other.cover];
    [self.headImageV sd_setImageWithURL:url placeholderImage:PICHOLDEER];

    
    if ([other.recommend isEqualToString:@"1"]) {
        _recommendLabel.hidden = NO;
    } else {
        _recommendLabel.hidden = YES;
    }
    
    [self.starView setStarWithNumber:(NSInteger)[self.other.rating intValue]];

    _nameLabel.text = other.name;
    
    _ratingUsers.text = [NSString stringWithFormat:@"%ld 点评", other.rating_users];
    
    _contentLabel.text = other.descriptions;
    _distance.text = [NSString stringWithFormat:@"%@ 人去过", other.visited_count];
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
